package engine.display
{
	import engine.data.ModelLocator;
	import engine.logic.AlertLogic;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	
	/**
	 *	战斗消息缓存 
	 * @author lw
	 * 
	 */
	public class AttAckMsgCacheLogic
	{
		/**
		 *	缓存队列 
		 */		
		private var _cacheList	: Array = [];
		
		private var _cacheAlert : Array = [];
		
		private var _model		: ModelLocator;
		
		private static	 var _self	:	AttAckMsgCacheLogic;
		
		public static function getInstance():AttAckMsgCacheLogic
		{
			if ( _self == null )
			{
				_self = new AttAckMsgCacheLogic();
			}
			return _self;
		}
		
		public function AttAckMsgCacheLogic()
		{
			_model = ModelLocator.getInstance();
		
			_model.addEventListener( String( CustomToClientFlag.SERVER_CUSTOMMSG_CLINET_BUFFER ), cacheAttackMsg );
		}
		
		public function cacheAlertMsg( type:int,strID:String,argArr:Array ):void
		{
			_cacheAlert.push( [ type, strID, argArr ] );
		}
		
		private function cacheAttackMsg(e : CustomMsgEvent):void
		{
			var pList : Array = e.pList;
			
			_cacheList.push( [ pList.shift(), pList ] );
			
			
		}
		
		public function clear():void
		{
			_cacheList = [];
		}
		
		public function sendAttackMsg():void
		{
			for( var i : int = 0; i < _cacheList.length; i++ )
			{
				_model.dispatchEvent( new CustomMsgEvent(_cacheList[i][ 0 ], _cacheList[i][ 1 ] ) );
			}
//			for( var j : int = 0; j < _cacheAlert.length; j++ )
//			{
//				AlertLogic.getInstance().AddAlert( _cacheAlert[ i ][ 0 ], _cacheAlert[ i ][ 1 ], _cacheAlert[ i ][ 2 ] );
//			}
			clear();
		}
		
		public function sendKissBossMsg():void
		{
			for( var i : int = 0; i < _cacheList.length; i++ )
			{
				if( _cacheList[ i ][ 0 ] == CustomToClientFlag.SERVER_CUSTOMMSG_FB_KILL_BOSS )
				{
					var msgArray : Array = _cacheList.splice( i, 1 )[ 0 ];
					_model.dispatchEvent( new CustomMsgEvent(msgArray[ 0 ], msgArray[ 1 ] ) );
					break;
				}
			}
		}
	}
}